import { message } from "ant-design-vue";

// 一键复制
export function clickCopy(val) {
  navigator.clipboard.writeText(val);
  message.success("复制成功！");
}

// 选中&点击/直接点击 进行复制
export function selectCopy(val) {
  let userSelection = null;
  if (window.getSelection) {
    //一般浏览器
    userSelection = window.getSelection();
  } else if (document.selection) {
    //IE浏览器、Opera
    userSelection = document.selection.createRange();
  }
  var strInput = "";
  try {
    strInput += " " + userSelection.toString();
  } catch (e) {
    //I兼容IE
    strInput += " " + userSelection.text;
  }
  navigator.clipboard.writeText(strInput == " " ? val : strInput);
  message.success("复制成功！");
}
